﻿/***************************************************/
/*** file:SocketInfo.cs                          ***/
/*** date:2010-08-07                             ***/
/*** author:huas                                 ***/
/*** function: struct of socket info             ***/
/***************************************************/



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using IM.Common;

namespace IM.Net
{
    struct SocketInfo
    {
        public NetHeader m_netHeader;
        public Socket m_socket;
        public byte[] m_szRecvBuffer;   //40k
        public byte[] m_szSendBuffer;   //40k

        public DateTime m_lastRecvTime;  //上次收包时间
        public bool m_bSendData;         //该客户端连上服务器后，是否向服务器发送了数据
        public int m_nNextIndex;         //下一个socket索引
        public int m_nPrevIndex;         //上一个socket索引
        public int m_nReadBeginIndex;    //接收数据的开始位置
        public int m_nReadEndIndex;      //接收数据的结束位置
        public bool m_bUsed; 
        public SocketAsyncEventArgs m_sendSocketArgs;

        public SocketAsyncEventArgs m_recvSocketArgs;

        public void Init(int nSendBufLen, int nRecvBufLen)
        {
            m_szRecvBuffer = new byte[nRecvBufLen];
            m_szSendBuffer = new byte[nSendBufLen];
            m_netHeader = new NetHeader();

            Clear();
        }

        public void Clear()
        {
            m_socket = null;
            m_nReadBeginIndex = 0;
            m_nReadEndIndex = 0;

            m_lastRecvTime = DateTime.MinValue;
            m_netHeader.m_createTime = 0;
            m_netHeader.m_nRecvPackCount = 0;
            m_netHeader.m_nSocketIndex = -1;
            m_netHeader.m_uSocketCount = 0;
            m_netHeader.m_userData = 0;
            m_netHeader.m_nInnerFlag = InnerFlag.INNERFLAG_NONE;

            m_bUsed = false;
            m_sendSocketArgs = null;
            m_recvSocketArgs = null;
        }
    }
}
